import request from '@/utils/request.js'

// 获取订单列表
export function getOrderList(params) {
  return request({
    url: '/api/orders/user',
    method: 'GET',
    params
  })
}
 // 获取用户订单
 export function getUserOrders(userId){
	 return request({
	       url: `api/orders/user/${userId}`,
	       method: 'get'
	})
 }

// 获取订单详情
export function getOrderDetail(id) {
  return request({
    url: `/api/orders/${id}`,
    method: 'GET'
  })
}

// 创建订单
export function createOrder(data) {
  return request({
    url: 'api/orders/create',
    method: 'POST',
    data
  })
}

// 取消订单
export function cancelOrder(id, reason) {
  return request({
    url: `/api/orders/${id}/cancel`,
    method: 'PUT',
    data: { reason }
  })
}

// 申请退款
export function applyRefund(id, data) {
  return request({
    url: `/api/orders/${id}/refund`,
    method: 'POST',
    data
  })
}

// 导出orderApi对象
export const orderApi = {
  getOrderList,
  getOrderDetail,
  createOrder,
  cancelOrder,
  applyRefund,
  getUserOrders
}
